package dao.impl;

import bean.Order;
import bean.OrderItem;
import dao.BaseDao;
import dao.OrderDao;

import java.util.List;

public class OrderDaoImpl extends BaseDao<Order> implements OrderDao {
    @Override
    public int saveOrder(Order order) {

        String sql = "insert into t_order(`order_code`,`create_time`,`price`,`status`,`user_id`)" +
                " values(?,?,?,?,?)";

        return update(sql, order.getOrderCode(), order.getCreateTime(), order.getPrice(), order.getStatus(), order.getUserId());
    }

    @Override
    public List<Order> queryOrdersByUserId(Integer userId) {
        try {
            String sql = "select `order_code` orderCode,`create_time` createTime,`price`,`status`," +
                    "`user_id` userId from t_order where user_id=?";
            return query(sql, userId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public int updateOrderStatus(String orderCode) {
        try {
            String sql="update `t_order` set status=? where `order_code`=?";
          return update(sql, "RECEIVED", orderCode);
        }catch (Exception e) {
            e.printStackTrace();
        }
               return -1;
    }


}
